package com.qiall.boot.fileservice.data.eitity.enums;

import com.qiall.common.exception.BusinessException;
import com.qiall.common.exception.ResultCode;
import com.qiall.common.service.BaseEnumsService;

public enum FileSourceTypeEnum implements BaseEnumsService {
    OSS((byte) 1, "OSS"),
    MINIO((byte) 2, "MINIO"),
    BAY_FILES((byte) 3, "BAY_FILES")
    ;

    private String desc;
    private byte code;

    FileSourceTypeEnum(byte code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    @Override
    public byte getCode() {
        return code;
    }

    public static FileSourceTypeEnum ofCode(byte code){
        for(FileSourceTypeEnum fileSourceTypeEnum:FileSourceTypeEnum.values()){
            if(fileSourceTypeEnum.code==code){
                return fileSourceTypeEnum;
            }
        }
        return null;
    }
    public static FileSourceTypeEnum ofDesc(String desc){
        for(FileSourceTypeEnum fileSourceTypeEnum:FileSourceTypeEnum.values()){
            if(fileSourceTypeEnum.desc.equals(desc)){
                return fileSourceTypeEnum;
            }
        }
        throw  new BusinessException(ResultCode.SYSTEM_ERROR,"枚举值不存在");
    }
}
